//
//  MainViewController.m
//  AwesomeProject
//
//  Created by apple on 2018/1/25.
//  Copyright © 2018年 Facebook. All rights reserved.
//

#import "MainViewController.h"
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
@interface MainViewController ()

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
  
  
  UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
  [button setTitle:@"high score" forState:UIControlStateNormal];
  [self.view addSubview:button];
  [button setFrame:CGRectMake(50, 100, 100, 30)];
  [button addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside];
    // Do any additional setup after loading the view.
}
-(void)buttonEvent:(UIButton*)button
{
 
    NSLog(@"High Score Button Pressed");
  
    NSURL * jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
  
//  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
//                                                      moduleName:@"AwesomeProject"
//                                               initialProperties:nil
//                                                   launchOptions:launchOptions];
//
//    NSURL *jsCodeLocation = [NSURL
//                             URLWithString:@"http://localhost:8081/index.bundle?platform=ios"];
    RCTRootView *rootView =
    [[RCTRootView alloc] initWithBundleURL : jsCodeLocation
                         moduleName        : @"MyApp"
                         initialProperties :
     @{
       @"scores" : @[
           @{
             @"name" : @"Alex",
             @"value": @"42"
             },
           @{
             @"name" : @"Joel",
             @"value": @"10"
             }
           ]
       }
                          launchOptions    : nil];
    UIViewController *vc = [[UIViewController alloc] init];
    vc.edgesForExtendedLayout = UIRectEdgeNone;
    vc.view = rootView;
    [self.navigationController pushViewController:vc animated:YES];
  
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
